<?php

namespace app\api\controller;
use app\api\common\Common;
use app\api\common\ApiErrDesc;

class Search extends Common {
    /**
     * 搜索记录接口
     * @return  [JSON]    [返回搜索记录信息]
     */
    public function search(){
        $data = $this->params;
        //获取热门搜索内容
        $remen = db('search_record')->group('keyword')->field('keyword')->order('SUM(num) desc')->limit(10)->select();
        dump($remen);exit();
        //获取历史搜索记录
        $history = array();
        if($data['uid']) {
            $history = db('search_record')->where('uid='.$data['uid'])->order('addtime desc')->field('keyword')->limit(20)->select();
            $this->return_msg(ApiErrDesc::SUCCESS[0], ApiErrDesc::SUCCESS[1], $history);
        }
        if($remen) {
			$this->return_msg(ApiErrDesc::SUCCESS[0], ApiErrDesc::SUCCESS[1], $remen);
		}else{
			$this->return_msg(ApiErrDesc::ERROR[0], ApiErrDesc::ERROR[1]);
		}
    }
}